import { config } from "../config";
var settings = require('./settings-service');

export class SyncStatus {
    static Current: SyncStatus = new SyncStatus();
    private status: any;
    constructor() {
        if (config.options.startId) {
            let lastStartInfo = settings.lastStartInfo;
            if (lastStartInfo && lastStartInfo.id == config.options.startId && lastStartInfo.status) {
                if (config.options.option && config.options.option.mode) {
                    delete config.options.option.mode;
                }
                settings.lastStartInfo = { id: config.options.startId, status: lastStartInfo.status++ };
            } else {
                settings.lastStartInfo = { id: config.options.startId, status: 1 };
            }
        }
        let pending = config.options.option
            && config.options.option.mode
            && (config.options.option.mode == 'c2l' || config.options.option.mode == 'l2c');
        this.status = pending ? 'pending' : 'ready';
    }

    isPending() {
        return this.status == 'pending';
    }

    isReady() {
        return this.status == 'ready';
    }

    setReady() {
        this.status = 'ready';
    }

    setForbid() {
        this.status = 'forbid';
    }

    setPending() {
        this.status = 'pending';
        config.options.option = config.options.option || {};
        config.options.option.mode = 'l2c';
    }

    setReset() {
        this.status = 'pending';
        config.options.option = config.options.option || {};
        config.options.option.mode = 'c2l';
    }

}